package com.supermate.supercut.infra.convertor;

import com.supermate.supercut.domain.enums.ResourceTypeEnum;
import com.supermate.supercut.domain.model.ClipboardText;
import com.supermate.supercut.domain.model.FileResource;
import com.supermate.supercut.infra.entity.ResourceDO;

import java.util.Objects;

/**
 * @author jiao.zhou
 */
public class ResourceConvertor {
    public static ResourceDO toResourceDo(ClipboardText clipboardText){
        ResourceDO resourceDO = new ResourceDO();
        resourceDO.setClipName(clipboardText.getClipboardName());
        resourceDO.setContent(clipboardText.getClipboardText());
        resourceDO.setGmtCreate(clipboardText.getGmtCreate());
        resourceDO.setGmtModify(clipboardText.getGmtModify());
        resourceDO.setViewTimes(clipboardText.getViewTimes());
        resourceDO.setResourceType(ResourceTypeEnum.TEXT.getCode());
        return resourceDO;

    }

    public static ResourceDO toResourceDo(FileResource fileResource){
        ResourceDO resourceDO = new ResourceDO();
        resourceDO.setClipName(fileResource.getClipboardName());
        resourceDO.setResourceName(fileResource.getFileName());
        resourceDO.setContent(fileResource.getRelativePath());
        resourceDO.setGmtCreate(fileResource.getUploadTime());
        resourceDO.setGmtModify(fileResource.getGmtModify());
        resourceDO.setViewTimes(fileResource.getDownLoadTimes());
        resourceDO.setResourceType(ResourceTypeEnum.FILE.getCode());
        return resourceDO;

    }

    public static ClipboardText toClipboardText(ResourceDO resourceDO) {
        if (Objects.isNull(resourceDO)) {
            return null;
        }
        ClipboardText clipboardText = new ClipboardText();
        clipboardText.setId(resourceDO.getId());
        clipboardText.setGmtCreate(resourceDO.getGmtCreate());
        clipboardText.setGmtModify(resourceDO.getGmtModify());
        clipboardText.setClipboardName(resourceDO.getClipName());
        clipboardText.setClipboardText(resourceDO.getContent());
        clipboardText.setViewTimes(resourceDO.getViewTimes());
        return clipboardText;
    }

    public static FileResource toFileResource(ResourceDO resourceDO) {
        if (Objects.isNull(resourceDO)) {
            return null;
        }
        FileResource fileResource = new FileResource();
        fileResource.setId(resourceDO.getId());
        fileResource.setFileName(resourceDO.getResourceName());
        fileResource.setClipboardName(resourceDO.getClipName());
        fileResource.setUploadTime(resourceDO.getGmtCreate());
        fileResource.setGmtModify(resourceDO.getGmtModify());
        fileResource.setDownLoadTimes(resourceDO.getViewTimes());
        fileResource.setRelativePath(resourceDO.getContent());
        return fileResource;
    }
}
